package com.qingke.easyjava;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.qingke.easyjava.mybatis.dao2.UserMapper;
import com.qingke.easyjava.mybatis.pojo2.User;

public class App2 {
	 public static void main(String[] args) {
	    	//mybatis的配置文件
	        String resource ="mybatis_conf.xml";
	        //使用类加载器加载mybaties的配置文件（它也加载关联的映射文件）
	        InputStream is =App.class.getClassLoader().getResourceAsStream(resource);
	        //构造sqlSession的工厂
	        SqlSessionFactory sessionFactory =new SqlSessionFactoryBuilder().build(is);
	        //创建能执行映射文件中sql的sqlSession
	        SqlSession session=sessionFactory.openSession();
	        UserMapper ium=session.getMapper(UserMapper.class);
//	        User user=ium.selectByPrimaryKey(3);
//	        System.out.println(user);
//	        
	        List<User> users=ium.getAllUsers();
	        for(User user:users){
	        	System.out.println(user);
	        }
	}
}
